import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    // imgUrl: 'https://www.yinyaoit.com', // 图片域名
    imgUrl: process.env.NODE_ENV == 'development' ? 'http://192.168.110.32:8888' : 'https://www.yinyaoit.com', // 图片域名
    imgUploadUrl: process.env.NODE_ENV == 'development' ? 'http://192.168.110.32:8888/api/Upload/uploadFile' : 'https://www.yinyaoit.com/api/Upload/uploadFile', // 图片上传
    env: '', // 开发环境
    baseUrl: '', // 接口域名
    userInfo: '', // 用户信息
    token: '', // 用户token
    refresh_token: '', // 用户刷新token key

    areaInfo: null,// 地区信息配置

    moduleBackgroundList: [],// 模块背景图列表
    systemConfig: {},// 系统配置
    // ...其他数据项

    isNeedRefreshOrderList: false,
    hotChatTypeList: [],// 热聊分类缓存
    IndexPopup: [],//首页弹窗是否关闭缓存

    showPrivacy: false, //隐私协议
    // 是否更改了地区id（用于切换地区后，重新获取新地区的数据；在程序启动时先获取一次）
    refreshFlag: {
      index: true,
      hotchat: true
    },
    firstCome: true,
  },
  getters: {
    env: state => state.env,
    baseUrl: state => state.baseUrl,
    userInfo: state => state.userInfo,
    token: state => state.token,
    refresh_token: state => state.refresh_token,
    showPrivacy: state => state.showPrivacy,
    firstCome: state => state.firstCome,
  },
  mutations: {
    setEnv(state, env) {
      state.env = env
    },
    setBaseUrl(state, baseUrl) {
      state.baseUrl = baseUrl
    },
    setIndexPopup(state, IndexPopup) {
      state.IndexPopup = IndexPopup;
    },
    setFirstCome(state, firstCome) {
      state.firstCome = firstCome;
    }
  },
  actions: {
    setUserInfo({
      state
    }, userInfo) {
      console.log(userInfo,'setUserInfo');
      
      state.userInfo = userInfo
    },
    setToken({
      state
    }, token) {
      state.token = token
    },
    setRefresh_token({
      state
    }, refresh_token) {
      state.refresh_token = refresh_token
    },
    // 设置模块背景图列表
    setModuleBackgroundList({
      state
    }, moduleBackgroundList) {
      state.moduleBackgroundList = moduleBackgroundList
    },
    // 设置系统配置
    setSystemConfig({
      state
    }, systemConfig) {
      state.systemConfig = systemConfig
    },
    isNeedRefreshOrderList({
      state
    }, flag) {
      state.isNeedRefreshOrderList = flag
    },

    // 设置地区信息配置
    setAreaInfo({
      state
    }, areaInfo) {
      state.areaInfo = areaInfo
    },
    setRefreshFlag({
      state
    }, type) {
      if (type == 'all') {
        state.refreshFlag = {
          index: true,
          hotchat: true
        }
      } else {
        state.refreshFlag[type] = false
      }
    },
    setHotChatTypeList({
      state
    }, hotChatTypeList) {
      state.hotChatTypeList = hotChatTypeList
    },

    setShowPrivacy({
      state
    }, showPrivacy) {
      state.showPrivacy = showPrivacy
    }

  }
})

export default store
